﻿using SharpDX;
using System;

namespace MikadoShooter
{
    [Serializable]
    public class Vector4Target : Vector4Base
    {
        public bool[] IsRemoved { get; private set; }

        [NonSerialized]
        private readonly Level level;

        public Vector4Target(int verticals, Level level) : base(verticals)
        {
            this.level = level;
            Init(verticals);
        }

        private void Init(int verticals)
        {
            IsRemoved = new bool[verticals];

            Vector4[] pos;
            int index;

            for (index = 0; index < verticals * 2; index += 4)
            {
                do
                {
                    pos = RandomExt.GetRandomPos();
                }
                while (Vector4.Distance(pos[0], pos[1]) < 0.1f);

                Add(index, pos[0], pos[1], RandomExt.GetRandomColor(level.Colors));
            }

            if (index != verticals * 2)
                throw new ApplicationException("Error CalcVerticals in drawShooter..");
        }

        private void Add(int offset, Vector4 pos1, Vector4 pos2, Vector4 color)
        {
            Data[offset + 0] = pos1;
            Data[offset + 1] = color;
            Data[offset + 2] = pos2;
            Data[offset + 3] = color;
        }
    }
}